package com.wxy.learn.classLoad;

/**
 * 运行方法
 *
 * @author wxy
 * @since 2023-01-08
 */
public class ClassLoadCase1Main {
    public static void main(String[] args) {
        /* 建议运行下面一次性仅运行一个方法比较清晰 */

        createParent();

        createChild();

        createParentAndChild();
    }

    private static void createParent() {
        /*
        输出:
        1. parent public static attr
        2. parent private static attr
        3. parent static code block
        4. parent anonymous inner class
        5. parent member variable code
        6. parent construct
         */
        /* 由上述输出可知: static修饰最先输出(谁在上面谁先执行, 一般都是public修饰在最上面)->
         匿名内部类和成员变量(谁在上面谁先执行)->最后是其构造方法 */
        Parent parent = new Parent();
    }

    private static void createChild() {
        /*
        1. parent public static attr
        2. parent private static attr
        3. parent static code block
        4. child static code block
        5. child private static attr
        6. child public static attr
        7. parent anonymous inner class
        8. parent member variable code
        9. parent construct
        10. child member variable code
        11. child anonymous inner class
        12. child construct
         */
        /* 由上述输出可知加载是顺序: 加载父类static->加载子类static->
        加载父类匿名内部类成员变量及构造->加载子类匿名内部类成员变量及构造 */
        Child child = new Child();
    }

    private static void createParentAndChild() {
        /*
        ---parent---
        1. parent public static attr
        2. parent private static attr
        3. parent static code block
        4. parent anonymous inner class
        5. parent member variable code
        6. parent construct

        ---child---
        7. child static code block
        8. child private static attr
        9. child public static attr
        10. parent anonymous inner class
        11. parent member variable code
        12. parent construct
        13. child member variable code
        14. child anonymous inner class
        15. child construct
         */
        /* 创建两个对象或者多个对象时, static修饰的常量或者变量仅加载一次
        (对比单独创建child和创建parent和child可知) */
        System.out.println("---parent---");
        Parent parent = new Parent();

        System.out.println("---child---");
        Child child = new Child();
    }
}
